#include "ProductTestCommon.h"

#define DEF_TAG             "TestCom"

void Ext_ProductTest_Get_SD_Result(char *result)
{
    if(DEF_COM_SUCCESS == Ext_InComFile_Access("/dev/mmcblk0p1"))
    {
        strcpy(result,"ok");
        return;
    }

    strcpy(result,"error");
    return;
}

void Ext_ProductTest_Get_WiFi_SSID(char *ssid)
{
    FILE *wifi_fp;
    int wifi_len;

    wifi_fp = popen("echo $UO_WIFI_SSID","r");
    if(!wifi_fp)
    {
        perror("popen wifi_fp");
        return;
    }
    fgets(ssid,PRODUCT_TEST_WIFI_SSID_LEN,wifi_fp);
    wifi_len = strlen(ssid);
    ssid[wifi_len-1] = '\0';
    printf("ssid = %s\n",ssid);
    pclose(wifi_fp);

    return;
}

void Ext_ProductTest_Get_Version(char *ver)
{
    FILE *version_fp;
    int version_len;

    version_fp = popen("cat /mnt/config/soc_version.txt | grep \"version\" | awk -F \"version=\" '{print $2}'","r");
    if(!version_fp)
    {
        perror("popen version_fp");
        return;
    }
    fgets(ver,PRODUCT_TEST_VERSION_LEN,version_fp);
    version_len = strlen(ver);
    ver[version_len-1] = '\0';
    printf("version = %s\n",ver);
    pclose(version_fp);

    return;
}

void Ext_ProductTest_Get_MCU_Mac(char *ver)
{
    FILE *mcu_mac_fp;
    int mcu_mac_len;

    if(Ext_InComFile_Access("/mnt/config/mcu_mac.txt") == DEF_COM_FILE_NOT_EXIST)
    {
        PRT_DBG(DEF_TAG,"no /mnt/config/mcu_mac.txt \n");
        return;
    }

    mcu_mac_fp = popen("cat /mnt/config/mcu_mac.txt","r");
    if(!mcu_mac_fp)
    {
        perror("popen mcu_mac_fp");
        return;
    }
    fgets(ver,PRODUCT_TEST_MCU_MAC_LEN,mcu_mac_fp);
    mcu_mac_len = strlen(ver);
    ver[mcu_mac_len] = '\0';
    printf("mcu_mac = %s\n",ver);
    pclose(mcu_mac_fp);

    return;
}

Com_void Ext_ProductTest_Change_BasicConfig(int type,int val)
{
    switch(type)
    {
    case INI_BASIC_VIDEO_FLIP :
    {
        Ext_SdkMediaCom_SetFlip(0);
    }
        break;

    case INI_BASIC_AUDIO_SPK_GAIN :
    {
        Ext_SdkMediaCom_SetSpkGain(val);
    }
        break;

    default:
        break;
    }
}

